<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>点餐系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <link rel="stylesheet" href="/css/app.css?v22"/>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/js/jquery.fly.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/jquery.qrcode.min.js"></script>
    <script type="text/javascript" src="/js/json2.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="/js/common.js?v8"></script>
    <script type="text/javascript" src="/js/SPA.js?v25"></script>
    <script type="text/javascript" src="/js/Cart.js?v12"></script>
    <script type="text/javascript" src="/js/ff.js?v1"></script>
    <script type="text/javascript" src="/js/cordova/cordova.js?v3"></script>
</head>
<body>

<div class="page-container">

</div>

<script th:inline="javascript">

    (function () {
        "use strict";

        /**
         * 手机端，点击效果补丁
         */
        function phonePatch() {
            $(document).on('touchstart', function (e) {
            });
            $(document).on('touchend', function (e) {
            });
        }

        phonePatch();
        window.OrderState = {
            confirmed: 0, //已确认订单
            wechat_payed: 1, //已通过微信支付的订单
            unconfirmed: 2, // 为确认订单
            cart_message: 3, // 购物车信息
            scan_qr_payed: 4, // 扫描
            offline_payed: 5,
            refused: 6
        }
        window.initCart = function () {
            console.log('initCart');
            var key = window.storeId + '_' + window.tableId;
            //服务员端，加载数据
            cart.load(key);
            cart.userId(window.userId);
            cart.storeId(window.storeId);
            cart.tableId(window.tableId);
        };

        window.initWaiter = function () {
            window.isWaiter = true;
            window.userId = $.cookie('cookie_user') || 'codysnail';//'ohmygod';//'idiscody'; //测试使用
            window.storeId = $.cookie('cookie_store_id');
            window.username = $.cookie('cookie_username');
            cart.storeId(window.storeId);
            cart.userId(window.userId);

            var spa = new SPA();
            window.spa = spa;
            spa.setOptions({
                index: '/snippet/waiter_tables.html',
                'waiter_preview': '/snippet/waiter_order.html',
                'waiter_order': '/snippet/waiter_order.html'
            });
            spa.start();
        };

        var isLogin = $.cookie('cookie_user');

        if (!isLogin) {
            console.log($.cookie('cookie_user'));
            var $container = $('.page-container');
            $container.load('/snippet/login.html', '_t=23', function (text, status, $xhr) {

            });
        } else {
            initWaiter();
        }

        $(document).on('deviceready',function(){
            console.log('cordova ready 2');
            var ip = common.getPref('ip');// || '192.168.1.106';
            if(!ip){

            }else{
                printer.connect(ip,function () {
                    console.log('connect success');
                    window.hasPrinter = true;
                },function () {
                    console.log('connect error');
                    window.hasPrinter = false;
                });
            }

        });

    }());
</script>
</body>
</html>